package com.example.sourcecodelearning.spring.factory;

import java.util.HashMap;
import java.util.Map;

/**
 * Bean注册器，用于注册和获取Bean
 */
public class BeanRegister {

    /**
     * 存放Bean名称和Bean对象的映射关系
     */
    private final Map<String, Object> singletonMap = new HashMap<>();

    public Object getSingletonBean(String beanName) {
        return singletonMap.get(beanName);
    }

    public void registerSingletonBean(String name, Object bean) {
        if (!singletonMap.containsKey(name)) {
            singletonMap.put(name, bean);
        }
    }

}
